import request from '@/utils/request';
import queryString from 'query-string';
import Constants from "@/utils/constants";

const urlQuery = queryString.parse(window.location.search);

const env = urlQuery && urlQuery.contextPath
          ?
          urlQuery.contextPath
          :
          `/trs`;
// const env = `/mock`;

export default {
  getTodoList(){
    // return request('trs_ymtc/user/viewUpdateForm.action?trsMastId=10753&format=json');
    return request(`${env}/user/toDo.action?&format=json`);
  },
  getProcessedList(){
    return request(`${env}/user/processed.action?&format=json`);
  },
  getApplicationList(){
    return request(`${env}/user/myApplications.action?&format=json`);
  },
  getDraftList(){
    return request(`${env}/user/myDraft.action?&format=json`);
  },
  getDetailData(params){
    const {action, query} = params;
    return request(`${env}/user/${action}.action?${query}&format=json`);
  },
  getSearchEmployee(data){
    return request(`${env}/exporthr/search.action?format=json&paginationSupport.startIndex=${data.index}&paginationSupport.countOnEachPage=${data.size}&orgId=${data.orgId}&keyWord=${data.keyword}`)
  },
  getOrgs(){
    return request(`${env}/exporthr/index.action?format=json`);
  },
  getApplicationInfo(){
    return request(`${env}/user/newRequest.action?format=json`);
  },
  saveApplication(data){
    return request(`${env}/user/createRequest.action?trsMast.companyCode=${data.companyCode}&trsMast.fabSite=${data.fabSite}&trsMast.isOneWay=${data.isOneWay}&trsMast.isOutboundTrip=${data.isOutboundTrip}&trsMast.formType=Travel+Request&format=json`);
  },
  saveDetailOfParams(data){
    let action = 'completeWorkflowEntry';
    if(data.actionType == 'viewWorkflowEntryAdv' || data.actionType == 'viewUpdateAdvanceInWorkFlow'){
      action = 'completeWorkflowEntryAdv';
    }
    const params = {
      path: `${env}/user/${action}.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveDraftDetail(data){
    const params = {
      path: `${env}/user/saveDraft.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  submitDetail(data){
    const params = {
      path: `${env}/user/submitMastForm.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  getWbsCodes(data){
    const params = {
      path: `${env}/user/viewWbsCode.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  queryCity(data){
    const params = {
      path: `${env}/user/queryCityInfo.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveAccommodationInfo(data){
    const params = {
      path: `${env}/user/saveAccommodationInfo.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveTicketInfo(data){
    const params = {
      path: `${env}/user/saveTicketInfo.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveTraveler(data){
    const params = {
      path: `${env}/user/saveTraveler.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveReimbursementInfo(data){
    const params = {
      path: `${env}/user/saveReimbursementInfo.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveAdvanceInfo(data){
    const params = {
      path: `${env}/user/saveAdvanceInfo.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  getAddReimbursementInfoLabel(id){
    return request(`${env}/user/viewAddReimbursementInfo.action?${id}&format=json`);
  },
  getExtraBtnsOfActionType(data, actionName){
    const params = {
      path: `${env}/user/${actionName}.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  getAddAdvanceInfoLabel(data){
    const params = {
      path: `${env}/user/viewAddAdvanceInfo.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  getAddTravellerLabel(){
    return request(`${env}/user/viewAddTraveler.action?format=json`);
  },
  getTicketInfoByCtrip(data){
    const params = {
      path: `${env}/user/saveTicketInfoCtrip.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  getAccommodationInfoByCtrip(data){
    const params = {
      path: `${env}/user/saveAccommodationInfoCtrip.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  delelteTicketInfoById(ticketId, id){
    return request(`${env}/user/delTicketInfo.action?ticketInfoId=${ticketId}&${id}&format=json`);
  },
  delelteTravellerById(travelerId, id){
    return request(`${env}/user/delTraveler.action?travelerId=${travelerId}&${id}&format=json`);
  },
  delelteAccommodationById(accId, id){
    return request(`${env}/user/delAccommodationInfo.action?accommodationInfoId=${accId}&${id}&format=json`);
  },
  delelteReimbursementById(orsItemId, id){
    return request(`${env}/user/delReimbursementInfo.action?orsItemId=${orsItemId}&${id}&format=json`);
  },
  saveViewWorkflowEntry(data){
    // 保存人员信息，以获取银行卡信息
    const params = {
      path: `${env}/user/viewWorkflowEntry.action?format=json`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  saveViewWorkflowEntryOfActualDetails(data){
    // 保存真实出差信息
    const params = {
      path: `${env}/user/viewWorkflowEntry.action?format=json&saveInfo=1`,
      method: 'POST',
      body: data
    }
    return request(params);
  },
  deleteAttachment(data){
    return request(`${env}/user/delProposalAttachment1.action?format=json&attachmentFileId=${data.fileId}&trsMastId=${data.trsMastId}`);
  },
  getDownloadFileUrl(id){
    return `${window.location.origin}${env}/user/download.action?attachmentFileId=${id}`;
  },
  getUploadFileUrl(){
    return `${window.location.origin}${env}/user/doProposalUpload1.action?format=json`;
  }
}
